from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SpecificationOption
from meiduo_admin.serializer.options import OptionsSerializer
from meiduo_admin.serializer.specificationOption import SpecificationOptionSerializer
from meiduo_admin.utils import PageNum

# 规格选项表的增删改查


class OptionsView(ModelViewSet):
    # 权限指定
    permission_classes = [IsAdminUser]
    # 序列化器指定
    serializer_class = OptionsSerializer
    # 分页器指定
    pagination_class = PageNum
    # 查询集指定
    queryset = SpecificationOption.objects.all()

    # 获取规格表信息
    def simple(self,request):
        # 查询所有规格表信息
        spec = SpecificationOption.objects.all()
        # 序列化返回
        ser = SpecificationOptionSerializer(spec, many=True)
        return Response(ser.data)


